//
//  DSSHTaskEndExplainVC.m
//  DSSH
//
//  Created by lcy on 16/4/15.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "DSSHTaskEndExplainVC.h"
#import "UIView+Round.h"
@interface DSSHTaskEndExplainVC ()<UITextViewDelegate>
{
    UILabel*labeltext;
}
@property(nonatomic,strong)UITextView*textView;
@property(nonatomic,strong)UIButton*submitBtn;
@property(nonatomic,strong)UIButton*cameraBtn;

@end

@implementation DSSHTaskEndExplainVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViewAndData];
    [self setupConstraints];
    // Do any additional setup after loading the view.
}
-(void)setupViewAndData
{
    self.title = @"结单说明";
    self.view.backgroundColor = [UIColor whiteColor];
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;
    UIBarButtonItem * backBarBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(backBarBtnClick)];
    self.navigationItem.leftBarButtonItem = backBarBtn;
    self.textView = [[UITextView alloc]init];
    [self.view addSubview:self.textView];
    self.submitBtn = [[UIButton alloc]init];
    [self.submitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [self.view addSubview:self.submitBtn];
    [self.textView getRoundView:5];
    self.textView.layer.borderWidth = 1;
    self.textView.delegate = self;
    self.textView.font = FONT(13);
    self.textView.layer.borderColor = [[UIColor groupTableViewBackgroundColor]CGColor];
    self.submitBtn.backgroundColor
    = COLOR_NAVIGATE_BAR;
    [self.submitBtn getRoundView:5];
    
    labeltext = [UILabel new];
    labeltext.font = FONT(13);
    labeltext.textColor = [UIColor grayColor];
    labeltext.text = @"请填写结单确认说明。";
    labeltext.frame = CGRectMake(7, 5, 200, 20);
    [self.textView addSubview:labeltext];
    
    self.cameraBtn = [UIButton new];
    [self.cameraBtn setImage:[UIImage imageNamed:@"xiangji"] forState:UIControlStateNormal];
    [self.view addSubview:self.cameraBtn];
}
-(void)setupConstraints
{
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(10);
        make.right.equalTo(self.view).with.offset(-10);
        make.top.equalTo(self.view).with.offset(10);
        make.height.mas_equalTo(100*HIGHT_SCALE);
    }];
    [self.cameraBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.textView.mas_right).with.offset(-10);
        make.bottom.equalTo(self.textView.mas_bottom).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(44*WIDTH_SCALE, 34*HIGHT_SCALE));
    }];
    
    [self.submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(20);
        make.right.equalTo(self.view).with.offset(-20);
        make.top.equalTo(self.textView.mas_bottom).with.offset(20);
        make.height.mas_equalTo(35*HIGHT_SCALE);
    }];
    
}
-(void)backBarBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {//检测到“完成”
        [textView resignFirstResponder];//释放键盘
        return NO;
    }
    if (textView.text.length==0){//textview长度为0
        if ([text isEqualToString:@""]) {//判断是否为删除键
            labeltext.hidden=NO;//隐藏文字
        }else{
            labeltext.hidden=YES;
        }
    }else{//textview长度不为0
        if (textView.text.length==1){//textview长度为1时候
            if ([text isEqualToString:@""]) {//判断是否为删除键
                labeltext.hidden=NO;
            }else{//不是删除
                labeltext.hidden=YES;
            }
        }else{//长度不为1时候
            labeltext.hidden=YES;
        }
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
